博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何安装svelte_解决Svelte模板中的承诺
阅读量:2502 次
发布时间:2019-05-11

本文共 1115 字,大约阅读时间需要 3 分钟。

如何安装svelte

Promises are an awesome tool we have at our disposal to work with asynchronous events in JavaScript.

Promise是一个很棒的工具,可用于处理JavaScript中的异步事件。

The relatively recent introduction of the await syntax in ES2017 made using promises even simpler.

ES2017中相对较新的await语法介绍使使用promise更加简单。

Svelte provides us the {#await} syntax in templates to directly work with promises at the template level.

Svelte在模板中为我们提供了{#await}语法,可直接在模板级别使用promise。

We can wait for promises to resolve, and define a different UI for the various states of a promise: unresolved, resolved and rejected.

我们可以等待承诺解决,并为承诺的各种状态定义不同的UI:未解决,已解决和已拒绝。

Here’s how it works. We define a promise, and using the {#await} block we wait for it to resolve.

运作方式如下。 我们定义一个承诺,并使用{#await}块等待它解决。

Once the promise resolves, the result is passed to the {:then} block:

承诺解决后,结果将传递到{:then}块:

{#await fetchImage}  

...waiting

{:then data} Dog image{/await}

You can detect a promise rejection by adding a {:catch} block:

您可以通过添加{:catch}块来检测承诺被拒绝:

{#await fetchImage}  

...waiting

{:then data} Dog image{:catch error}

An error occurred!

{/await}

Run the example:

运行示例: :

翻译自:

如何安装svelte

转载地址:http://rxqgb.baihongyu.com/

你可能感兴趣的文章
ng-深度学习-课程笔记-2: 神经网络中的逻辑回归(Week2)
查看>>
正则表达式的搜索和替换
查看>>
个人项目:WC
查看>>
地鼠的困境SSL1333 最大匹配
查看>>
flume+elasticsearch+kibana遇到的坑
查看>>
Javascript 高阶函数等
查看>>
【MM系列】在SAP里查看数据的方法
查看>>
C#——winform
查看>>
CSS3 transform制作的漂亮的滚动式导航
查看>>
《小强升职记——时间管理故事书》读书笔记
查看>>
Alpha 冲刺(3/10)
查看>>
Kaldi中的Chain模型
查看>>
spring中的ResourceBundleMessageSource使用和测试示例
查看>>
css规范 - bem
查看>>
SQL 通用数据类型
查看>>
UVALive 6145 Version Controlled IDE(可持久化treap、rope)
查看>>
mysql 将两个有主键的表合并到一起
查看>>
底部导航栏-----FragmentTabHost
查看>>
在linux中安装jdk以及tomcat并shell脚本关闭启动的进程
查看>>
apk,task,android:process与android:sharedUserId的区别
查看>>